<!-- 这是文章详情页 -->
<template>
  <div id="articleId">
    <div class="title">{{ state.title }}</div>
    <div class="infos">
      <div class="info">发表人： {{ state.author }}</div>
      <div class="info">发表时间： {{ dateFromatUTC(state.time) }}</div>
    </div>
    <div class="des" v-html="state.text"></div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'

import { useRoute } from 'vue-router'

import currScroll from '@/hooks/scroll'

import { dateFromatUTC } from '@/utils/convserTime'

import { getArticleInfo, getEditorInfo } from '@/server/client/api_article'

// 记录浏览进度
currScroll()

const route = useRoute()

const state = reactive({
  title: '',
  author: '',
  time: '',
  text: ''
})

getArticleInfo(route.params.id as string).then(({ data }) => {
  state.title = data.data?.articleInfo.title!
  state.author = data.data?.articleInfo.author.name!
  state.time = data.data?.articleInfo.time!
  getEditorInfo(data.data?.articleInfo.textURL!).then(
    ({ data: articleText }) => {
      state.text = articleText.data?.editor!
    }
  )
})
</script>

<style scoped lang="less">
#articleId {
  width: 1200px;
  margin: 0 auto;
  padding: 50px 0;
  .title {
    color: #333333;
    font-size: 25px;
    white-space: nowrap;
    width: 1200px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 700;
  }
  .infos {
    display: flex;
    margin: 30px 0;
    border-bottom: 1px solid #efe9e9;
    padding-bottom: 30px;
    .info {
      color: #adadad;
      font-size: 13px;
      margin-right: 20px;
    }
  }
}
</style>
